import java.io.*;
import java.lang.management.BufferPoolMXBean;
import java.util.ArrayList;
import java.util.Scanner;

public class Demo03{
    ArrayList<Student> list = new ArrayList<>();
    Student s = new Student(null,null,null);
    Scanner sc = new Scanner(System.in);
    public void toList() throws IOException {
        while (true) {
            System.out.println("请输入姓名：");
            String name = sc.next();
            System.out.println("请输入班级：");
            String banJi = sc.next();
            System.out.println("请输入年龄：");
            String age = sc.next();
            s.setName(name);
            s.setBanJi(banJi);
            s.setAge(age);
            list.add(s);
            System.out.println("是否继续添加信息？y or n");
            String choice = sc.next();
            if (choice.equals("n")) {
                break;
            }
        }
        File path = new File("c:\\Users\\86195\\IdeaProjects\\IODemo\\student.txt");
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(path),"gbk");
        for (int i = 0; i < list.size(); i++) {
            outputStreamWriter.write(s.getName()+'\t');
            outputStreamWriter.write(s.getBanJi()+'\t');
            outputStreamWriter.write(s.getAge()+'\n');
        }
        outputStreamWriter.close();
    }
}
